import os
import traceback
from model.dsddifftagreader import get_dsd_tag, get_dsd_singleTag
from model.dsdreusetags import reuse_ID3_chunk, replace_ID3_chunk
from model.id3tag import new_ID3_tag
from view.tagviewer import view_tag, view_path_selector, view_input_single_tag, view_selector, view_file_editor, view_dir_editor

choice  = view_selector()

if(choice=="file"):
    view_file_editor()
elif(choice=="dir"):
    view_dir_editor()

#inFileName, outPath, allFlag = view_path_selector()

#if (inFileName != ""):
#    pathName, inFileName = os.path.split(inFileName)
#    base_name = os.path.splitext(inFileName)[0]
#    file_extension = os.path.splitext(inFileName)[1]

#    inFiles= []
#    outFiles = []

#    if(allFlag==1):
#        with os.scandir(pathName) as it:
#            for i in it:
#                if i.name.endswith(".dff"):
#                    base_name = os.path.splitext(i.name)[0]
#                    file_extension = os.path.splitext(i.name)[1]
#                    inFiles.append(os.path.join(pathName, i.name))
#                    outFiles.append(os.path.join(outPath, base_name+"_out"+file_extension))
    #                print(i)
    #                print(inFiles)
    #                print(outFiles)
#    else:
#        inFiles.append(os.path.join(pathName, inFileName))
#        outFiles.append(os.path.join(outPath, base_name+"_out"+file_extension))
    #    print(inFiles, outFiles)

#    album, artist, title = get_dsd_tag(inFiles[0])

#    if(album!=""):
#        album = album[1:].decode('utf-8')
#    if(artist!=""):
#        artist = artist[1:].decode('utf-8')
#    if(title!=""):
#        title = title[1:].decode('utf-8')

#    ch = view_tag(album, artist, title)
#    if ch == "Ok":
#        for i in range(len(inFiles)):
#            reuse_ID3_chunk(inFiles[i], outFiles[i])
#    elif ch=="New":
#        for i in range(len(inFiles)):
#            newTag, singleTag = view_input_single_tag(inFiles[i])
#            if newTag == "Ok":
#                replace_ID3_chunk(inFiles[i], outFiles[i],new_ID3_tag(singleTag))
